# 在故障节点上重启 ZooKeeper
/usr/local/zookeeper/bin/zkServer.sh restart

# 检查节点状态
/usr/local/zookeeper/bin/zkServer.sh status


# 在新节点上安装和配置 ZooKeeper
wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar -xzf apache-zookeeper-3.7.0-bin.tar.gz
mv apache-zookeeper-3.7.0-bin /usr/local/zookeeper

# 配置 zoo.cfg
cat <<EOF > /usr/local/zookeeper/conf/zoo.cfg
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zookeeper1:2888:3888
server.2=zookeeper2:2888:3888
server.3=zookeeper3:2888:3888
EOF

# 创建数据目录和 myid 文件
mkdir -p /var/lib/zookeeper
echo "4" > /var/lib/zookeeper/myid

# 启动 ZooKeeper
/usr/local/zookeeper/bin/zkServer.sh start



# 停止故障节点
/usr/local/zookeeper/bin/zkServer.sh stop

# 恢复数据
cp /path/to/backup/version-2 /var/lib/zookeeper/version-2

# 重启节点
/usr/local/zookeeper/bin/zkServer.sh start


# 调整 ZooKeeper 配置
cat <<EOF > /usr/local/zookeeper/conf/zoo.cfg
tickTime=3000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=10
syncLimit=5
server.1=zookeeper1:2888:3888
server.2=zookeeper2:2888:3888
server.3=zookeeper3:2888:3888
EOF

# 重启 ZooKeeper 节点
/usr/local/zookeeper/bin/zkServer.sh restart

